<template>

    <!-- 查看课程 -->
    <el-select
      class="!w-60 my-4 ml-2"
      v-model="selectTeacher"
      placeholder="请选择查看的老师"
      @change="select"
    >
      <el-option v-for="item in setClass" :key="item.label" :label="item.label" :value="item.label">
      </el-option>
    </el-select>
    <!-- <el-input
      placeholder="请输入学生姓名"
      v-model="stuName"
      class="stu-name"
      clearable
      v-if="isAdmin"
    >
    </el-input> -->
    <!-- <el-button :icon="Search" @click="search" class="search-btn" circle v-if="isAdmin"></el-button> -->
    <el-table
      :data="tableData"
      style="width: 100% ;"
      :default-sort="{ prop: 'time', order: 'descending' }"
    >
      <!-- <el-table-column prop="Student_Name" label="学号" width="100"> </el-table-column> -->
      <el-table-column prop="Course_Name" label="课程名字" width="100"> </el-table-column>
      <el-table-column prop="Grade" label="年级" width="100"> </el-table-column>
      <el-table-column prop="Teacher_Name" label="上课老师" width="100"> </el-table-column>
      <el-table-column prop="Major" label="所属专业" width="180"> </el-table-column>
      <el-table-column label="删除" v-if="isTeacher != 'teacher'">
        <template v-slot="scope">
          <el-button
            type="danger"
            :icon="Delete"
            circle
            @click="remove(scope.row.id, scope.$index)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="mt-6 flex justify-center">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="10"
        :total="max"
        @current-change="page($event)"
      >
      </el-pagination>
    </div> -->
  </template>



<script setup>

    import { ref, computed , onMounted} from "vue";
    import { useRouter } from "vue-router";
    import { Delete, Search } from "@element-plus/icons-vue";


    import selectCourse from "@/modules/course/select-course";

    let isAdmin = localStorage.id == "admin";
    let isTeacher = localStorage.id;
    let router = useRouter();
    let tableData = ref([]);
    let selectTeacher = ref("");
    /**
     * 初始化加载
     * @param {*} 
     */
    const  init = async () =>{

        try {
            
            let res =  await selectCourse();

            if(res.status === 200){

                tableData.value = res.data

            }else{

                tableData.value = [];
                
            }

        } catch (error) {
            console.error('Error fetching data:', error);
        }
    }


    onMounted(()=>{
        init();
    })


    const select = (val) => { 
        console.log(val);
    }


</script>



<style scoped lang="scss">

</style>


